package com.qf.service.impl;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 路由策略
 */
@Service(value = "router")
@Slf4j
public class RouterFilterServiceImpl implements FilterChainService {

    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private AmqpAdmin amqpAdmin;
    
    @Override
    public boolean strategy(StandardSubmit standardSubmit) throws Exception {
        log.info("执行路由策略");

        String queue = RabbitMQConstants.TOPIC_SMS_GATEWAY+1;
        amqpAdmin.declareQueue(QueueBuilder.durable(queue).build());//创建队列
        rabbitTemplate.convertAndSend(queue,standardSubmit);//发送队列给指定交换机
        log.info("路由策略执行成功");
        return true;

    }
}
